/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.ClienteDao;
import pe.edu.upc.dew.sisrest.model.Cliente;

/**
 *
 * @author Aldo
 */
@Repository
public class ClienteDaoHibernate extends HibernateDaoSupport implements ClienteDao{

    @Autowired
    public ClienteDaoHibernate (SessionFactory sessionFactory){
        setSessionFactory(sessionFactory);
    }

    @Override
    public List<Cliente> obtenerClientes() {
        return getHibernateTemplate().find(" from Cliente");
    }

    @Override
    public Cliente obtenerCliente(String sId) {
        return (Cliente) getHibernateTemplate().get(Cliente.class, sId);
        //return (Cliente)getSession().createQuery("from Cliente "+
        //        "where ndoc=?").setString(sId, sId).uniqueResult();
    }

    @Override
    public void grabarCliente(Cliente objCli) {
        getHibernateTemplate().saveOrUpdate(objCli);
    }

    @Override
    public void eliminarCategoria(String sId) {
        Cliente oCli = obtenerCliente(sId);
        getHibernateTemplate().delete(oCli);
    }

}
